//
//  rewardMoneyAlert.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/24.
//

#import "rewardMoneyAlert.h"
#import "CommonUtil.h"
#import "RewardMoneyView.h"
#import "GiveFlowerView.h"

@interface rewardMoneyAlert()

@property (strong, nonatomic) UIButton * leftBtn;
@property (strong, nonatomic) UIButton * rightBtn;
@property (strong, nonatomic) UIButton * cancelBtn;
@property (strong, nonatomic) UIView * indexView;
@property (strong, nonatomic) UIView * lineView;

@property (strong, nonatomic) RewardMoneyView * rewardView;
@property (strong, nonatomic) GiveFlowerView * giveView;

@end

@implementation rewardMoneyAlert

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.whiteView];
        self.whiteView.layer.cornerRadius = AD(10);
    }
    return self;
}

-(void)show{
    self.whiteView.frame = CGRectMake(0, SCREEN_HEIGHT-AD(500), SCREEN_WIDTH, AD(500));
    [self.whiteView addSubview:self.leftBtn];
    [self.whiteView addSubview:self.rightBtn];
    [self.whiteView addSubview:self.cancelBtn];
    [self.whiteView addSubview:self.indexView];
    [self.whiteView addSubview:self.rewardView];
    [self.whiteView addSubview:self.giveView];
    [self.whiteView addSubview:self.lineView];
    
    [self leftBtnClick:nil];
}

- (void)leftBtnClick:(UIButton *)sender{
    self.leftBtn.selected = YES;
    self.rightBtn.selected = false;
    
    if (sender) {
        [UIView animateWithDuration:0.25 animations:^{
            self.indexView.centerX = sender.centerX;
        }];
    }else{
        self.indexView.centerX = self.leftBtn.centerX;
    }
    [UIView animateWithDuration:0.25 animations:^{
        self.rewardView.left = 0;
        self.giveView.left = SCREEN_WIDTH;
    }];

    
}
- (void)rightBtnClick:(UIButton *)sender{
    self.leftBtn.selected = false;
    self.rightBtn.selected = YES;
    [UIView animateWithDuration:0.25 animations:^{
        self.indexView.centerX = sender.centerX;
        self.rewardView.left = -SCREEN_WIDTH;
        self.giveView.left = 0;
    }];
}

- (void)cancelBtnClick:(UIButton *)sender{
    [self dismiss];
}

- (void)rechargeBtnClick:(UIButton *)sender{
    [self dismiss];
    BaseAlert *alert = [HudFactory creatHudWithType:@"BuyRedFlower"];
    [alert show];
}


-(UIButton *)leftBtn{
    if (!_leftBtn) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftBtn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_leftBtn setTitle:@"红包打赏" forState:UIControlStateNormal];
        [_leftBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_leftBtn setTitleColor:RGB(255.0, 90.0, 117.0) forState:UIControlStateSelected];
        _leftBtn.titleLabel.font = [UIFont systemFontOfSize:AD(18)];
        _leftBtn.frame = CGRectMake(AD(10), AD(5), AD(100), AD(45));
    }
    
    return _leftBtn;
}

-(UIButton *)rightBtn{
    if (!_rightBtn) {
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_rightBtn setTitle:@"赠送小红花" forState:UIControlStateNormal];
        [_rightBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_rightBtn setTitleColor:RGB(255.0, 90.0, 117.0) forState:UIControlStateSelected];
        _rightBtn.titleLabel.font = [UIFont systemFontOfSize:AD(18)];
        _rightBtn.frame = CGRectMake(AD(110), AD(5), AD(110), AD(45));
    }
    
    return _rightBtn;
}

-(UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _cancelBtn.frame = CGRectMake(SCREEN_WIDTH-AD(50), AD(18), AD(25), AD(25));
        [_cancelBtn setImage:[UIImage imageNamed:@"icon_chacha"] forState:UIControlStateNormal];
        [_cancelBtn setImage:[UIImage imageNamed:@"icon_chacha"] forState:UIControlStateHighlighted];
    }
    return _cancelBtn;
}


-(UIView *)indexView{
    if (!_indexView) {
        _indexView = [[UIView alloc] initWithFrame:CGRectMake(0, _leftBtn.bottom, AD(80), AD(2))];
        _indexView.backgroundColor = RGB(255.0, 90.0, 117.0);
    }
    return _indexView;
}

-(UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, AD(65),SCREEN_WIDTH, AD(1))];
        _lineView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.6];
    }
    return _lineView;
}

-(RewardMoneyView *)rewardView{
    if (!_rewardView) {
        _rewardView = [[RewardMoneyView alloc] initWithFrame:CGRectMake(0, self.lineView.bottom,SCREEN_WIDTH, self.whiteView.height-self.lineView.bottom)];
        [_rewardView.rechargeBtn addTarget:self action:@selector(rechargeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _rewardView;
}
-(GiveFlowerView *)giveView{
    if (!_giveView) {
        _giveView = [[GiveFlowerView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, self.lineView.bottom,SCREEN_WIDTH, self.whiteView.height-self.lineView.bottom)];
        [_giveView.rechargeBtn addTarget:self action:@selector(rechargeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _giveView;
}



@end
